package com.itools.core.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class ZipUtils {
    private static int BUFFER_SIZE = 1024;

    public ZipUtils() {
    }

    public static void toZip(List<File> files, OutputStream outputStream) throws RuntimeException {
        long start = System.currentTimeMillis();
        ZipOutputStream zipOutputStream = null;

        try {
            zipOutputStream = new ZipOutputStream(outputStream);
            Iterator var5 = files.iterator();

            while(var5.hasNext()) {
                File file = (File)var5.next();
                byte[] buf = new byte[BUFFER_SIZE];
                zipOutputStream.putNextEntry(new ZipEntry(file.getName()));
                FileInputStream in = new FileInputStream(file);

                int len;
                while((len = in.read(buf)) != -1) {
                    zipOutputStream.write(buf, 0, len);
                }

                zipOutputStream.closeEntry();
                in.close();
            }

            long end = System.currentTimeMillis();
            System.out.println("压缩完成，耗时：" + (end - start) + " ms");
        } catch (Exception var17) {
            throw new RuntimeException("zip error from ZipUtils", var17);
        } finally {
            if (zipOutputStream != null) {
                try {
                    zipOutputStream.close();
                } catch (IOException var16) {
                    var16.printStackTrace();
                }
            }

        }
    }
}